home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8482 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  7.7 KB

  1. Path: goanna.cs.rmit.EDU.AU!not-for-mail
  2. From: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
  4. Subject: Re: Number representation (was: Hungarian notation - whoops!)
  5. Date: 19 Feb 1996 18:44:31 +1100
  6. Organization: Comp Sci, RMIT, Melbourne, Australia
  7. Message-ID: <4g99ov$gir@goanna.cs.rmit.EDU.AU>
  8. References: <30C40F77.53B5@swsbbs.com>
  9. NNTP-Posting-Host: goanna.cs.rmit.edu.au
  10. X-Newsreader: NN version 6.5.0 #0 (NOV)
  11.  
  12. tsw@3do.com (Tom Watson) writes:
  13.  
  14. >In article <4fms62$c0p@goanna.cs.rmit.EDU.AU>, ok@goanna.cs.rmit.EDU.AU
  15. >(Richard A. O'Keefe) wrote:
  16.  
  17. >> 
  18. >> >By the way, S&M is of course the right representation of floating-point,
  19. >> >using 2's complement for floating-point is a goof that only a designer
  20. >> >not understanding fpt would make!
  21. >> 
  22.  
  23. I did _not_ write that, I _quoted_ it.
  24.  
  25. >I'm not so sure.  With sign & magnitude you get TWO representations of the
  26. >same number (zero).
  27.  
  28. In the B6700, you did indeed get two representations of 0, but unless you
  29. used some non-standard extensions
  30.     (-0 .EQ. 0) but (.NOT.(-0 .IS. 0))
  31. nothing in your program could depend on this fact.  The presence of two
  32. signed integer zeros (which were the same as the two signed floating point
  33. zeros) was something that a programmer could and did completely ignore.
  34. All the hardware had to do was to make sure that -0 and +0 acted the same
  35. in ordinary comparisons.
  36.  
  37. >Some may argue that the difference is that negative
  38. >zero is what a very small negative number decays into, and positive zero
  39. >is what a very small positive number decays into.
  40.  
  41. That is not the way it worked in the B6700 or the DECsystem-10.  So you
  42. have two representations of 0 with identical arithmetic properties.  So
  43. what?  Comparison hardware has to worry, programmers don't.  The VAX
  44. uses (used?) a sign-and-magnitude format, but never generated -0.0 and
  45. regarded the "-0.0" representation as an "illegal operand".
  46.  
  47. As for IEEE arithmetic, I find that it helps to think of it as having
  48. NO representation for 0.  Instead, it can represent
  49.     -1/epsilon,
  50.         <negative finite numbers>,
  51.         -epsilon
  52.         <NO zero>
  53.         +epsilon
  54.         <positive finite numbers>
  55.     +1/epsilon
  56.  
  57. >My understanding of numbers (no, I'm not an expert at this!)  is that
  58. >zero is only ONE number (basically without sign).  Most numbering
  59. >systems (like two's complement integers) have put in the positive
  60. >domain.
  61.  
  62. >Programs didn't need to test for
  63. >multiple incantations of zero (which needs to be done with IEEE numbers if
  64. >the hardware doesn't detect BOTH forms).
  65.  
  66. Should "incantations" be "incarnations"?
  67. If the hardware doesn't process +0 and -0 and process them distinctly,
  68. isn't IEEE.
  69.  
  70. >As far as I can see, the only good thing (tm) that multiple (+ & -) zeros
  71. >gets you is multiple infinities when you divide by it (which may be the
  72. >object).  As long as both positive and negative numbers exist, and there
  73. >is SOME method of making a bit pattern happen for each of them that are
  74. >defined, it probably doesn't mean much which bits are turned on (use gray
  75. >code, I don't care).  Just make sure that all the operations necessary are
  76. >working, and give proper (documented) results.
  77.  
  78. I think I should make it clear that when I criticised twos-complement as
  79. silly because it significantly complicates the arithmetic model that the
  80. programmer has to work with, I was not particularly concerned about the
  81. hardware representation of numbers.  To a programmer who "grew up" with
  82. a machine having 48 data bits of which numbers used only 47, it is obvious
  83. that the connection between numbers and bits is only conventional.  (For
  84. example, you could pack 6 EBCDIC characters per word using bit instructions,
  85. but try to do it using integer arithmetic and you were sure of an overflow.)
  86.  
  87. What I care about is programs running on "hopefully sufficiently large"
  88. machines that turn out _not_ to be "sufficiently large" being quietly
  89. given wrong answers.
  90.  
  91. There are occasions when Ada 95's modular types are exactly the right thing
  92. to use.  There are many more when plain integer types are right, and I'm
  93. glad that Ada _encourages_ overflow detection.
  94.  
  95.  
  96. From ok Mon Feb 19 18:10 EST 1996
  97. Received: (from ok@localhost) by goanna.cs.rmit.EDU.AU (8.7.1/8.6.9) id SAA15322; Mon, 19 Feb 1996 18:10:40 +1100 (EST)
  98. Date: Mon, 19 Feb 1996 18:10:40 +1100 (EST)
  99. From: "Richard A. O'Keefe" <ok>
  100. Message-Id: <199602190710.SAA15322@goanna.cs.rmit.EDU.AU>
  101. To: ok
  102. Subject: follow failed
  103. Content-Type: text
  104. Content-Length: 1504
  105.  
  106. posted, but mailed to the moderator for approval.
  107.  
  108. Your response has been saved in ~/dead.letter
  109.  
  110. Your article follows:
  111. Newsgroups: comp.lang.c.moderated
  112. Subject: Re: But DO C hackers code concisely?
  113. References: <4fa7e7$2pu@solutions.solon.com> <4fst4u$2f1@solutions.solon.com> <4fvh88$e3l@solutions.solon.com>
  114.  
  115. "Robert F. Monroe" <Robert@hever.demon.co.uk> writes:
  116. >What conceivable use could there be for either printf or scanf in a 
  117. >Windows DLL? The very nature of Windows I/O would cause them to only 
  118. >produce garbage.
  119.  
  120. Well, the C standard *requires* them.  If you haven't got printf() and
  121. scanf(), you haven't got a "hosted" C implementation. 
  122.     printf(~~1~~)        ===    fprintf(stdout, ~~1~~)
  123. and    scanf(~~2~~)        ===    fscanf(stdin, ~~2~~)
  124. so the problem is not printf and scanf per se but stdin and stdout, and
  125. if you haven't got _them_ you haven't got a conforming "hosted" C
  126. implementation either.
  127.  
  128. One very good reason for having them in the library is precisely to catch
  129. code which has been ported to Windows but incompletely.  Since Microsoft C
  130. has exceptions, I would think it appropriate for
  131.     - input from stdin, however expressed
  132.     - output to stdout, however expressed
  133. to raise an exception, and for the library to define printf &c so that user
  134. code cannot accidentally rely on defining them to do something different.
  135. getchar, putchar, printf, scanf, could all share the same few "raise
  136. exception" bytes.
  137.  
  138. In any case, this is irrelevant to the original example, which used
  139.     sprintf
  140. not printf.
  141.  
  142.  
  143. From ok Mon Feb 19 18:17 EST 1996
  144. Received: (from ok@localhost) by goanna.cs.rmit.EDU.AU (8.7.1/8.6.9) id SAA15797; Mon, 19 Feb 1996 18:17:38 +1100 (EST)
  145. Date: Mon, 19 Feb 1996 18:17:38 +1100 (EST)
  146. From: "Richard A. O'Keefe" <ok>
  147. Message-Id: <199602190717.SAA15797@goanna.cs.rmit.EDU.AU>
  148. To: ok
  149. Subject: follow failed
  150. Content-Type: text
  151. Content-Length: 1348
  152.  
  153. posted, but mailed to the moderator for approval.
  154.  
  155. Your response has been saved in ~/dead.letter
  156.  
  157. Your article follows:
  158. Newsgroups: comp.lang.c.moderated
  159. Subject: Re: But DO C hackers code concisely?
  160. References: <4fa7e7$2pu@solutions.solon.com> <4fst4u$2f1@solutions.solon.com>
  161.  
  162. I gave the example of complex code that could have been replaced by
  163. tiny calls to sprintf.
  164.  
  165. Michael Smith <msmith@mpx.com.au> writes:
  166. >Yes I do think that MS leaving these functions out is realy stupid,
  167. >but you have to work with the tools you have.
  168.  
  169. This doesn't in the least spoil my argument.  Assume that leaving the
  170. printf() and scanf() _families_ out of the library used with DLLs is a
  171. good decision, and ignoring wsprintf(),
  172. (a) This wasn't a DLL, it was a complete program.
  173. (b) Converting integers from binary to text is pretty useful.  If sprintf()
  174.     is not available, or if efficiency is a concern and sprintf() proves slow,
  175.     the answer is to write functions
  176.  
  177.     struct Integer_Format {
  178.         unsigned char base;    /* 2, 8, 10, 16 */
  179.         unsigned char pad ;
  180.         unsigned char width; /* a minimum value */
  181.     };
  182.     static const struct Integer_Format plain = {10, ' ', 1};
  183.  
  184.     ltostr(char *buf, long val, struct Integer_Format *);
  185.     ultostr(char *buf, unsigned long val, struct Integer_Format *);
  186.  
  187.     or something similar, and stick them in your personal library.
  188.  
  189.  
  190. -- 
  191. Election time; but how to get Labour _out_ without letting Liberal _in_?
  192. Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.
  193.